package wnhz.com.business.uitls;

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import org.xutils.common.util.LogUtil;

import java.text.DecimalFormat;

/**
 * 
* @ClassName: CommonUtils 
* @Description: 
* @author yiw
* @date 2015-12-28 下午4:16:01 
*
 */
public class CommonUtils {

	public static void showSoftInput(Context context, View view){
		InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
		//imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
	}
	
	public static void hideSoftInput(Context context, View view){
		InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //强制隐藏键盘
	}
	
	public static boolean isShowSoftInput(Context context){
		InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
		//获取状态信息
		return imm.isActive();//true 打开
	}
	//double 仅保留有效位
	public static String doubleToString(double num){
		//使用0.00不足位补0，#.##仅保留有效位
		DecimalFormat df = new DecimalFormat("0.00");
		String format = df.format(num);
		LogUtil.e("====doubleToString1==="+format);
		LogUtil.e("====doubleToString2==="+format.substring(0, format.indexOf(".")));
		LogUtil.e("====doubleToString3==="+format.substring(format.indexOf("."), format.indexOf(".")+2));
		String substring = format.substring(0, format.indexOf("."))+format.substring(format.indexOf("."), format.indexOf(".")+3);
		LogUtil.e("====doubleToString4==="+substring);
		return substring;
	}
}
